/*************************************************************************
  > File Name   : LinkList.h
  > Author      : zhoutk
  > Mail        : zhoutk@189.cn
  > Created Time: 六  4/16 17:56:11 2016
 ************************************************************************/

#ifndef _LINKLIST_H
#define _LINKLIST_H
#endif

#include <iostream>
using namespace std;
template<class T>
struct elem{
    T coef;
    T exp;
    elem *next;
};
template<class T>
class LinkList{
public:
    elem<T> *first;
    LinkList(){ first = new elem<T>; first->next = NULL; }
    //void Insert(int coef,int exp);
    void InsertTail(T cofe,T exp);    //向链表的尾部插入元素
    void InitializeTail(T datas[], T n); //尾插法初始化链表
    void DisplayList();//输出链表中的元素
    
};
//链表尾部插入元素
template<class T>void LinkList<T>::InsertTail(T c, T e){
    elem<T> *node = first;
    while (node->next != NULL) node = node->next;
    elem<T> *n = new elem<T>;
    
    n->coef = c;
    n->exp = e;
    node->next = n;
    n->next = NULL;
}
template<class T>void LinkList<T>::InitializeTail(T datas[],T n){
    for (int i = 0; i < 2 * n; i = i + 2) InsertTail(datas[i], datas[i + 1]);
}
template<class T>void LinkList<T>::DisplayList(){
    elem<T> *s = first->next;
    while (s){
        cout << s->coef << " " << s->exp<<"   ";
        s = s->next;
    }
    cout << endl;
}
